package rsa

import (
	"strings"
)

const (
	pkcs8PriPemBegin = "-----BEGIN PRIVATE KEY-----\n"
	pkcs8PriPemEnd   = "\n-----END PRIVATE KEY-----"
	pkcs8PubPemBegin = "-----BEGIN PUBLIC KEY-----\n"
	pkcs8PubPemEnd   = "\n-----END PUBLIC KEY-----"
)

func formatPkcs8PrivateKey(key string) string {
	if !strings.HasPrefix(key, pkcs8PriPemBegin) {
		key = pkcs8PriPemBegin + key
	}
	if !strings.HasSuffix(key, pkcs8PriPemEnd) {
		key = key + pkcs8PriPemEnd
	}
	return key
}

func formatPkcs8PublicKey(key string) string {
	if !strings.HasPrefix(key, pkcs8PubPemBegin) {
		key = pkcs8PubPemBegin + key
	}
	if !strings.HasSuffix(key, pkcs8PubPemEnd) {
		key = key + pkcs8PubPemEnd
	}
	return key
}
